<template>
  <div style="height: 100%;overflow:hidden" class="main">
    <x-header :left-options="{preventGoBack:true,backText: ''}" @on-click-back="backhome">安全检查单填写</x-header>
    <div class="main-container" style="overflow:auto;height:93%">
      <v-touch v-on:swiperight="onSwipeRight" :swipe-options="{direction: 'horizontal'}">
        <!-- <div id="map"></div> -->
        <div>
          <group>
            <!-- <cell title='项目部'
                  v-model="proDept"
                  is-link
                  link='proList1'></cell>
            <cell title="工程项目"
                  v-model="pro"
                  is-link
                  link="proList1">
            </cell>-->
            <select-project
              title="项目部"
              formType="inspection"
              module="danger"
              status="add"
              :showValue="true"
              v-model="proDept"
              @selectPro="selectPro"
            ></select-project>
            <div style="height: 1px;background: #eeeeee;"></div>
            <select-project
              title="工程项目"
              formType="inspection"
              module="danger"
              status="add"
              :showValue="true"
              v-model="pro"
              @selectPro="selectPro"
            ></select-project>
            <calendar v-model="checkDate" title="检查日期" disable-future @on-change="dateChange"></calendar>
            <popup-radio title="是否回复"
                         :options="options"
                         v-model="isReply"
                         @on-hide="isReplyFuc"></popup-radio>
            <popup-picker
              title="类别"
              :data="fatherClass"
              v-model="FATHERCLASS"
              @on-hide="selectCheckPro"
            ></popup-picker>
            <popup-picker
              title="检查项目"
              :data="checkPro"
              v-model="CHECKPRO"
              @on-hide="selectCheckItems"
            ></popup-picker>
            <popup-picker
              title="检查项"
              :data="checkItems"
              v-model="CHECKITEMS"
              @on-hide="selectChildClass"
              v-show="isReplyFlag"
            ></popup-picker>
          </group>
          <group title="描述">
            <x-textarea placeholder="请输入一段描述" v-model="DESCRIPTION"></x-textarea>
          </group>
          <group title="检查图片">
            <picture-upload :pageToken="pageToken" v-model="fieldToken"></picture-upload>
          </group>
          <group>
            <cell title="填写人" v-model="name"></cell>
            <cell title="联系电话" v-model="phone"></cell>
            <cell title="填写部门" v-model="dept"></cell>
            <cell title="填写时间" v-model="inputDate"></cell>
          </group>
          <div style="text-align:center;display:flex" class="top-border">
            <button
              :disabled="isDisable"
              class="userBack-button_save"
              @click="saveInspectionInfo"
            >保存</button>
            <Toast :value="toastValue" :is-show-mask="true" text="保存成功" @on-hide="saveSuccess"></Toast>
            <Toast
              :value="toastValueErr"
              :is-show-mask="true"
              :text="err"
              @on-hide="saveErr"
              type="cancel"
              width="200px"
            ></Toast>
          </div>
        </div>
      </v-touch>
    </div>
  </div>
</template>
 
<script>
import * as L from "leaflet";
//Vue.L = Vue.prototype.$L = L
import {
  Group,
  Cell,
  XButton,
  Box,
  GroupTitle,
  Flexbox,
  FlexboxItem,
  Divider,
  Calendar,
  PopupPicker,
  Toast,
  Loading
} from "vux";
var map = null;
var marker = null;
var flag = 0;
export default {
  components: {
    XButton,
    Box,
    GroupTitle,
    Group,
    Flexbox,
    FlexboxItem,
    Divider,
    Group,
    Cell,
    Calendar,
    PopupPicker,
    Toast,
    Loading
  },
  name: "HelloWorld",
  data() {
    return {
      msg: "Welcome to Your Vue.js App",
      proDept:
        this.$route.query.pmname === undefined
          ? this.$route.query.proDept
          : this.$route.query.pmname,
      pmid:
        this.$route.query.pmid === ""
          ? this.$route.query.proId
          : this.$route.query.pmid,
      proId:
        this.$route.query.pmid === ""
          ? this.$route.query.proId
          : this.$route.query.pmid,
      //pmname: this.$route.query.pmname,
      pro: this.$route.query.pro,
      prjId: this.$route.query.proId,
      centerPosition: this.$route.query.centerPosition,
      site: this.$route.query.centerPosition,
      fatherClass: [],
      FATHERCLASS: [],
      //FatherClass:[fatherClass],
      checkPro: [],
      CHECKPRO: [],
      checkItems: [],
      CHECKITEMS: [],
      CHILDCLASS: "",
      IMPORTANCE: "",
      WEIGHT: "",
      name: this.$store.state.user.ADUSER_NAME,
      userName: this.$store.state.user.loginId,
      phone: this.$store.state.user.mobil,
      dept: this.$store.state.user.orgName,
      DESCRIPTION: "",
      pageToken: "",
      fieldToken: "",
      buttonid: "",
      // inputDate: this.$store.state.user.loginTime,
      inputDate: "",
      inputDateFix: "",
      // map:"",
      checkDate: this.$store.state.user.loginTime,
      month: "",
      year: "",
      checkMy: "",
      quarter: "",
      toastValue: false,
      toastValueErr: false,
      err: "",
      checkDateFix: "",
      offlineUrl: [],
      isDisable: false,
      options: ["是", "否"],
      isReply:"是",
      isReplyFlag:true,
    };
  },
  methods: {
    isReplyFuc(){
      if(this.isReply == "否"){
        this.isReplyFlag=false
      }else{
        this.isReplyFlag=true
      }
    },
    selectPro(val) {
      this.proId = val.pid === "" ? val.id : val.pid;
      this.proDept = val.pname;
      this.pmid = val.pid === "" ? val.id : val.pid;
      this.prjId = val.id;
      this.pro = val.name;
      this.centerPosition = val.site;
      this.site = val.site;
    },
    onSwipeRight() {
      this.$router.push({
        path: "/hidangereport_new",
        query: {
          proId: this.prjId,
          proDept: this.proDept,
          pro: this.pro,
          site: this.centerPosition,
          pmid: this.pmid
        }
      });
    },
    //     openSumlist(item) {
    //     //this.$store.commit('SET_CURRENT_ROW', item);
    //     this.$router.push({path:'/hidangereport',query:{pro:""}})
    // },
    dateChange() {
      var date = this.checkDate;
      this.checkDateFix = this.checkDate + " 00:00:00.000";
      console.log(this.checkDateFix);
      var month = date.substr(5, 2);
      var year = date.substr(0, 4);
      var checkMy = date.substr(0, 7);
      date = new Date(date);
      var dtMonth = date.getMonth();
      var quarter = 0;
      if (dtMonth < 3) {
        quarter = 1;
      } else if (dtMonth < 6) {
        quarter = 2;
      } else if (dtMonth < 9) {
        quarter = 3;
      } else {
        quarter = 4;
      }
      // this.checkDate=date;
      this.month = month;
      //console.log(this.month);
      this.year = year;
      //console.log(this.year);
      this.checkMy = checkMy;
      //console.log(this.checkMy);
      this.quarter = quarter;
      //console.log(this.quarter);
    },
    backhome() {
      // this.$router.push('/hidangereport');
      if (this.checkNetWork()) {
        this.$router.push({
          path: "/hidangereport_new",
          query: {
            pmid: this.pmid,
            proId: this.prjId,
            proDept: this.proDept,
            pro: this.pro,
            site: this.centerPosition,
            isSelected:true
          }
        });
        this.$vux.loading.hide();
      } else {
        //执行离线状态时的任务
        this.$router.push({
          path: "/offlinehidangerlist",
          query: {
            pmid: this.pmid,
            proId: this.prjId,
            proDept: this.proDept,
            pro: this.pro,
            site: this.centerPosition
          }
        });
      }
    },
    saveInspectionInfo() {
      this.isDisable = true;
      console.log("项目部名称：", this.proDept);
      this.err = "";
      if (!this.pro) {
        this.err += "【工程项目】不能为空<br/>";
      }
      if (this.checkDate == "") {
        this.err += "【检查日期】不能为空<br/>";
        //console.log(this.FATHERCLASS.length)
      }
      if (this.FATHERCLASS.length == 0) {
        this.err += "【类别】不能为空<br/>";
      }
      if (this.CHECKPRO.length == 0) {
        this.err += "【检查项目】不能为空<br/>";
      }
      if (this.CHECKITEMS.length == 0 && this.isReplyFlag==true) {
        this.err += "【检查项】不能为空<br/>";
      }
      // if (this.DESCRIPTION == []) {
      //   this.err += "【描述】不能为空<br/>";
      // }
      // if (this.fieldToken == '') {
      //   this.err += "【检查图片】不能为空<br/>"
      // }
      if (this.err != "") {
        this.toastValueErr = true;
        this.isDisable = false;
        return false;
      }
      if (this.checkNetWork()) {
        var params = {
          _method: "formService.saveFormData",
          requestEventData: {
            eventType: "formSubmitEvent",
            formType: 1,
            bizObjId: "PMHSE_INSPECTION",
            formId: "PMHSE_INSPECTION_ADD",
            buttonId: this.buttonid
          },
          _OBJ_NAME_: "PMHSE_INSPECTION",
          _FORM_ID_: "PMHSE_INSPECTION_ADD",
          useType: "add",
          pageToken: this.pageToken,
          formData: {
            objName: "PMHSE_INSPECTION",
            pks: ["GUID"],
            data: [
              {
                rowData: [
                  {
                    DataTarget: "GUID",
                    Value: "",
                    OriginalValue: null,
                    PK: true,
                    DataType: "String"
                  },
                  {
                    DataTarget: "RESTATE",
                    Value: "0",
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "PRODEPT",
                    Value: this.proDept,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CONSTRUCTPRO",
                    Value: this.pro,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "PROJECTID",
                    Value: this.prjId,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "SYSPRJID",
                    Value: this.proId,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CENTERPOSITION",
                    Value: this.site,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKDATE",
                    Value: this.checkDateFix,
                    OriginalValue: null,
                    PK: false,
                    DataType: "DATE"
                  },
                  {
                    DataTarget: "CHECKMONTH",
                    Value: this.month,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKYEAR",
                    Value: this.year,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKMY",
                    Value: this.checkMy,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "FATHERCLASS_TEXT",
                    Value: this.FATHERCLASS.toString(),
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "FATHERCLASS",
                    Value: this.FATHERCLASS.toString(),
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKPRO_TEXT",
                    Value: this.CHECKPRO.toString(),
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKPRO",
                    Value: this.CHECKPRO.toString(),
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKQUARTER",
                    Value: this.quarter,
                    OriginalValue: null,
                    PK: false,
                    DataType: "int"
                  },
                  {
                    DataTarget: "CHECKITEMS_TEXT",
                    Value: this.CHECKITEMS.toString(),
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKITEMS",
                    Value: this.CHECKITEMS.toString(),
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "SECURITYLEVEL",
                    Value: "一般",
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHILDCLASS",
                    Value: this.CHILDCLASS,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "IMPORTANCE",
                    Value: this.IMPORTANCE,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "WEIGHT",
                    Value: this.WEIGHT,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "SYSTODAY",
                    Value: this.inputDate,
                    OriginalValue: null,
                    PK: false,
                    DataType: "TimeStamp"
                  },
                  {
                    DataTarget: "DESCRIPTION",
                    Value: this.DESCRIPTION,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "HIDDENNUM",
                    Value: 0,
                    OriginalValue: null,
                    PK: false,
                    DataType: "int"
                  },
                  {
                    DataTarget: "PROSCORE",
                    Value: 0,
                    OriginalValue: null,
                    PK: false,
                    DataType: "int"
                  },
                  {
                    DataTarget: "ACTSCORE",
                    Value: 0,
                    OriginalValue: null,
                    PK: false,
                    DataType: "int"
                  },
                  {
                    DataTarget: "ATTACHMENTS",
                    Value: this.fieldToken,
                    OriginalValue: null,
                    PK: false,
                    DataType: "Store.ecidiDoc"
                  },
                  {
                    DataTarget: "INPUTERFULLNAME",
                    Value: this.name,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "INPUTERNAME",
                    Value: this.userName,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "PHONENUM",
                    Value: this.phone,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "INPUTERDEPTNAME",
                    Value: this.dept,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "INPUTDATE",
                    Value: this.inputDate,
                    OriginalValue: null,
                    PK: false,
                    DataType: "TimeStamp"
                  },
                  {
                    DataTarget: "ISREPLY",
                    Value: this.isReply,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  }
                ],
                children: []
              }
            ]
          },
          _ATTACHMENT_DELETE_IDS_: "",
          formInfo: {
            GUID: "",
            RESTATE: "1",
            CONSTRUCTPRO: this.pro,
            SYSPRJID: this.proId,
            CENTERPOSITION: this.centerPosition,
            CHECKDATE: this.checkDateFix,
            CHECKMONTH: this.month,
            CHECKYEAR: this.year,
            CHECKMY: this.checkMy,
            FATHERCLASS_TEXT: this.FATHERCLASS.toString(),
            FATHERCLASS: this.FATHERCLASS.toString(),
            CHECKPRO_TEXT: this.CHECKPRO.toString(),
            CHECKPRO: this.CHECKPRO.toString(),
            CHECKQUARTER: this.quarter.toString(),
            CHECKITEMS_TEXT: this.CHECKITEMS.toString(),
            CHECKITEMS: this.CHECKITEMS.toString(),
            SECURITYLEVEL: "一般",
            CHILDCLASS: this.CHILDCLASS,
            IMPORTANCE: this.IMPORTANCE,
            WEIGHT: this.WEIGHT,
            SYSTODAY: this.inputDate,
            DESCRIPTION: this.DESCRIPTION,
            HIDDENNUM: "0",
            PROSCORE: "0",
            ACTSCORE: "0",
            ATTACHMENTS: this.fieldToken,
            INPUTERFULLNAME: this.name,
            INPUTERNAME: this.userName,
            PHONENUM: this.phone,
            INPUTERDEPTNAME: this.dept,
            INPUTDATE: this.inputDate,
            ISREPLY:this.isReply
          }
        };
        let json = {
          FixJSON: JSON.stringify(params)
        };

        this.$ajax({
          url: this.COMMON_URL, //+ '?_viewId=PMHSE_INSPECTION',
          method: "post",
          // data: this.signMD5(json)
          data: json
        })
          .then(res => {
            //console.log(res);
            this.$vux.loading.show({
              text: "Loading"
            });
            this.toastValue = true;
            //console.log("");
          })
          .catch(err => {
            setTimeout(() => {
              this.isDisable = false;
            }, 1000);
            console.log(err);
            alert(err);
            //this.err='';
          });
      } else {
        //执行离线状态时的任务
        let offline = this.$store.state.offlineflieurl;
        console.log("offline", offline);
        let urlOFFLINE = [];
        for (let i = 0; i < offline.length; i++) {
          let flies = offline[i].url.replace(/\./g, "||");
          // let fliess=flies.replace(/,/g,'_')
          urlOFFLINE.push(flies);
        }
        let offlineStr = urlOFFLINE.join(",");
        // urlOFFLINE = JSON.stringify(urlOFFLINE)
        console.log("urlOFFLINE", urlOFFLINE);
        this.$store.state.SQLiteDB.transaction(
          tx => {
            tx.executeSql(
              'INSERT INTO PMHSE_INSPECTION (GUID, RESTATE, PRODEPT, PROJECTID, CONSTRUCTPRO, SYSPRJID, CENTERPOSITION, CHECKDATE, CHECKMONTH, CHECKYEAR ,CHECKMY,FATHERCLASS_TEXT,FATHERCLASS,CHECKPRO_TEXT,CHECKPRO,CHECKQUARTER,CHECKITEMS_TEXT,CHECKITEMS,SECURITYLEVEL,CHILDCLASS,IMPORTANCE,WEIGHT,SYSTODAY,DESCRIPTION,HIDDENNUM,PROSCORE,ACTSCORE,ATTACHMENTS,INPUTERFULLNAME,INPUTERNAME,PHONENUM,INPUTERDEPTNAME,INPUTDATE,FILEURL,ISREPLY) VALUES ("' +
                this.guid() +
                '", "' +
                "1" +
                '", "' +
                this.proDept +
                '","' +
                this.prjId +
                '","' +
                this.pro +
                '", "' +
                this.proId +
                '","' +
                this.centerPosition +
                '","' +
                this.checkDateFix +
                '","' +
                this.month +
                '","' +
                this.year +
                '","' +
                this.checkMy +
                '","' +
                this.FATHERCLASS.toString() +
                '","' +
                this.FATHERCLASS.toString() +
                '","' +
                this.CHECKPRO.toString() +
                '","' +
                this.CHECKPRO.toString() +
                '","' +
                this.quarter.toString() +
                '","' +
                this.CHECKITEMS.toString() +
                '","' +
                this.CHECKITEMS.toString() +
                '","' +
                "一般" +
                '","' +
                this.CHILDCLASS +
                '","' +
                this.IMPORTANCE +
                '","' +
                this.WEIGHT +
                '","' +
                this.inputDate +
                '","' +
                this.DESCRIPTION +
                '","' +
                "0" +
                '","' +
                "0" +
                '","' +
                "0" +
                '","' +
                this.fieldToken +
                '","' +
                this.name +
                '","' +
                this.userName +
                '","' +
                this.phone +
                '","' +
                this.dept +
                '","' +
                this.inputDate +
                '","' +
                offlineStr +
                '","' +
                this.isReply +
                '")'
            );

            // tx.executeSql('SELECT * FROM PMHSE_INSPECTION', [],(tx,result)=>{
            // console.log('mylist',result)
            // let res =  result.rows[0].FILEURL
            // res = res.replace(/\|\|/g,".")
            // this.offlineUrl = res.split(",")
            // })
          },
          err => {
            console.log(err);
          }
        );

        this.toastValue = true;
      }
    },
    // saveInspectionInfo () {
    //   var params = {
    //     "_method": "formService.saveFormData",
    //     "requestEventData": {          "eventType": "formSubmitEvent",
    //       "formType": 1,
    //       "bizObjId": "PMHSE_INSPECTION",
    //       "formId": "PMHSE_INSPECTION_ADD",
    //       "buttonId": this.buttonid        },
    //     "_OBJ_NAME_": "PMHSE_INSPECTION",
    //     "_FORM_ID_": "PMHSE_INSPECTION_ADD",
    //     "useType": "add",
    //     "pageToken": this.pageToken,
    //     "formData": {
    //       "objName": "PMHSE_INSPECTION",
    //       "pks": ["GUID"],
    //       "data": [{            "rowData":
    //           [{ "DataTarget": "GUID", "Value": "", "OriginalValue": null, "PK": true, "DataType": "String" },
    //           { "DataTarget": "RESTATE", "Value": "0", "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "PRODEPT", "Value": this.proDept, "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "CONSTRUCTPRO", "Value": this.pro, "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "PROJECTID", "Value": this.prjId, "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "SYSPRJID", "Value": this.proId, "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "CENTERPOSITION", "Value": this.site, "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "CHECKDATE", "Value": this.checkDateFix, "OriginalValue": null, "PK": false, "DataType": "DATE" },
    //           { "DataTarget": "CHECKMONTH", "Value": this.month, "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "CHECKYEAR", "Value": this.year, "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "CHECKMY", "Value": this.checkMy, "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "FATHERCLASS_TEXT", "Value": this.FATHERCLASS.toString(), "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "FATHERCLASS", "Value": this.FATHERCLASS.toString(), "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "CHECKPRO_TEXT", "Value": this.CHECKPRO.toString(), "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "CHECKPRO", "Value": this.CHECKPRO.toString(), "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "CHECKQUARTER", "Value": this.quarter, "OriginalValue": null, "PK": false, "DataType": "int" },
    //           { "DataTarget": "CHECKITEMS_TEXT", "Value": this.CHECKITEMS.toString(), "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "CHECKITEMS", "Value": this.CHECKITEMS.toString(), "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "SECURITYLEVEL", "Value": "一般", "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "CHILDCLASS", "Value": this.CHILDCLASS, "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "IMPORTANCE", "Value": this.IMPORTANCE, "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "WEIGHT", "Value": this.WEIGHT, "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "SYSTODAY", "Value": this.inputDate, "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
    //           { "DataTarget": "DESCRIPTION", "Value": this.DESCRIPTION, "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "HIDDENNUM", "Value": 0, "OriginalValue": null, "PK": false, "DataType": "int" },
    //           { "DataTarget": "PROSCORE", "Value": 0, "OriginalValue": null, "PK": false, "DataType": "int" },
    //           { "DataTarget": "ACTSCORE", "Value": 0, "OriginalValue": null, "PK": false, "DataType": "int" },
    //           { "DataTarget": "ATTACHMENTS", "Value": this.fieldToken, "OriginalValue": null, "PK": false, "DataType": "Store.ecidiDoc" },
    //           { "DataTarget": "INPUTERFULLNAME", "Value": this.name, "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "PHONENUM", "Value": this.phone, "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "INPUTERDEPTNAME", "Value": this.dept, "OriginalValue": null, "PK": false, "DataType": "String" },
    //           { "DataTarget": "INPUTDATE", "Value": this.inputDate + " 00:00:00.000", "OriginalValue": null, "PK": false, "DataType": "TimeStamp" }], "children": []          }]        },
    //     "_ATTACHMENT_DELETE_IDS_": "",
    //     "formInfo": {          "GUID": "",
    //       "RESTATE": "1", "CONSTRUCTPRO": this.pro, "SYSPRJID": this.proId,
    //       "CENTERPOSITION": this.centerPosition,
    //       "CHECKDATE": this.checkDateFix,
    //       "CHECKMONTH": this.month,
    //       "CHECKYEAR": this.year,
    //       "CHECKMY": this.checkMy,
    //       "FATHERCLASS_TEXT": this.FATHERCLASS.toString(),
    //       "FATHERCLASS": this.FATHERCLASS.toString(),
    //       "CHECKPRO_TEXT": this.CHECKPRO.toString(),
    //       "CHECKPRO": this.CHECKPRO.toString(),
    //       "CHECKQUARTER": this.quarter.toString(),
    //       "CHECKITEMS_TEXT": this.CHECKITEMS.toString(),
    //       "CHECKITEMS": this.CHECKITEMS.toString(),
    //       "SECURITYLEVEL": "一般",
    //       "CHILDCLASS": this.CHILDCLASS,
    //       "IMPORTANCE": this.IMPORTANCE, "WEIGHT": this.WEIGHT, "SYSTODAY": this.inputDate,
    //       "DESCRIPTION": this.DESCRIPTION, "HIDDENNUM": "0", "PROSCORE": "0", "ACTSCORE": "0",
    //       "ATTACHMENTS": this.fieldToken,
    //       "INPUTERFULLNAME": this.name, "PHONENUM": this.phone, "INPUTERDEPTNAME": this.dept, "INPUTDATE": this.inputDate        }

    //   }
    //   let json = {
    //     FixJSON: JSON.stringify(params),
    //   }
    //   this.err = '';
    //   if (!this.pro) {
    //     this.err += "【工程项目】不能为空<br/>";
    //   }
    //   if (this.checkDate == '') {
    //     this.err += "【检查日期】不能为空<br/>";
    //     //console.log(this.FATHERCLASS.length)
    //   }
    //   if (this.FATHERCLASS.length == 0) {
    //     this.err += "【类别】不能为空<br/>";
    //   }
    //   if (this.CHECKPRO.length == 0) {
    //     this.err += "【检查项目】不能为空<br/>";
    //   }
    //   if (this.CHECKITEMS.length == 0) {
    //     this.err += "【检查项】不能为空<br/>";
    //   }
    //   if (this.DESCRIPTION == []) {
    //     this.err += "【描述】不能为空<br/>";
    //   }
    //   if (this.fieldToken == '') {
    //     this.err += "【检查图片】不能为空<br/>"
    //   }
    //   if (this.err != "") {
    //     this.toastValueErr = true;
    //     return false;
    //   }

    //   this.$ajax({
    //     url: this.COMMON_URL + '?_viewId=PMHSE_INSPECTION',
    //     method: 'post',
    //     data: json
    //   }).then(res => {
    //     //console.log(res);
    //     this.toastValue = true;
    //     //console.log("");
    //   }).catch((err) => {
    //     console.log(err);
    //     alert(err);
    //     //this.err='';
    //   });

    // },
    selectFather() {
      //console.log("点击成功")
      //this.fatherClass=[[""]];
      var params = {
        _method: "component.getBatchDatas",
        _param: {
          controls: {
            FATHERCLASS_TEXT: {
              orgConfig: {
                Filter: "1=1",
                Fields: "FATHERCLASS,FATHERCLASS_TEXT",
                BizObj: "PMHSE_SUBCLASSW",
                Service: "selectFather1",
                componentType: "ECIDIHTMLSelect"
              },
              dataConfig: {
                Method: "component.getListData",
                Param: {
                  bizObj: "PMHSE_SUBCLASSW",
                  service: "selectFather1",
                  fields: "FATHERCLASS,FATHERCLASS_TEXT",
                  filter: "1=1",
                  currentPageIndex: 1,
                  pageSize: 999999,
                  orderList: [{ field: "m", order: "asc" }],
                  QueryFormData: ""
                },
                componentType: "ECIDIHTMLSelect"
              },
              storeType: "Data"
            }
          }
        }
      };
      let json = {
        FixJSON: JSON.stringify(params)
      };
      this.$ajax({
        url: this.COMMON_URL, //+ '?_viewId=PMHSE_INSPECTION',
        method: "post",
        // data: this.signMD5(json)
        data: json
      }).then(res => {
        console.log("adsasda", res);
        var i = 0;
        for (i = 0; i < res.data.datas.FATHERCLASS_TEXT.length; i++) {
          //debugger
          this.fatherClass[i] = [
            res.data.datas.FATHERCLASS_TEXT[i].FATHERCLASS
          ];
          //console.log(this.fatherClass);
        }
        this.fatherClass = [this.fatherClass];
        //console.log(this.fatherClass);
      });
    },
    selectFatherOffline() {
      // debugger
      this.$store.state.SQLiteDB.transaction(tx => {
        tx.executeSql("SELECT * FROM PMHSE_SUBCLASSW ", [], (tx, result) => {
          console.log("pro", result);
          let subPrj = result.rows;
          var i = 0;
          for (i = 0; i < subPrj.length; i++) {
              this.fatherClass[i] = [subPrj.item(i).FATHERCLASS];
          }
          this.fatherClass = [this.fatherClass];
        });
      });
    },
    selectCheckPro(type) {
      if (this.checkNetWork()) {
        this.CHECKPRO = [];
        this.CHECKITEMS = [];
        if (type) {
          var params = {
            _method: "PMHSE_INSPECTION.selectCheckProF",
            CODE_TYPE: this.FATHERCLASS.join("")
          };
          let json = {
            FixJSON: JSON.stringify(params)
          };
          this.$ajax({
            url: this.COMMON_URL, //+ "?_viewId=PMHSE_INSPECTION",
            method: "post",
            data: json
            // params:this.signMD5({_method: "PMHSE_INSPECTION.selectCheckProF", CODE_TYPE: this.FATHERCLASS.join("") })
          }).then(res => {
            console.log(res);
            var i = 0;
            for (i = 0; i < res.data.list.length; i++) {
              this.checkPro[i] = [res.data.list[i].CHECKPRO];
            }
            this.checkPro = [this.checkPro];
          });
        }
      } else {
        this.CHECKPRO = [];
        this.CHECKITEMS = [];
        //执行离线状态时的任务
        let fatherclass = this.FATHERCLASS.join("");
        if (type) {
          this.$store.state.SQLiteDB.transaction(tx => {
            tx.executeSql(
              'SELECT * FROM PMHSE_CHECKLISTW WHERE FATHERCLASS="' +
                fatherclass +
                '"',
              [],
              (tx, result) => {
                console.log("pro", result);
                let subPrj = result.rows;
                var i = 0;
                for (i = 0; i < subPrj.length; i++) {
                  this.checkPro[i] = [subPrj.item(i).CHECKPRO];
                }
                this.checkPro = [this.checkPro];
              }
            );
          });
        }
      }
    },
    selectCheckItems(type) {
      // this.CHECKITEMS = [];
      // if (type) {
      //   let params = {
      //     FixJSON: { "_method": "PMHSE_INSPECTION.selectCheckItems", "FATHERCLASS": this.FATHERCLASS.join(""), "CODE_TYPE": this.CHECKPRO.join("") }
      //   }
      //   this.$ajax({
      //     url: this.COMMON_URL + "?_viewId=PMHSE_INSPECTION",
      //     method: 'post',
      //     params: params
      //   }).then(res => {
      //     //console.log(res)
      //     this.CHILDCLASS = res.data.list[0].CHILDCLASS;
      //     var i = 0;
      //     for (i = 0; i < res.data.list.length; i++) {
      //       this.checkItems[i] = [res.data.list[i].CHECKITEMS];
      //     }
      //     this.checkItems = [this.checkItems]
      //   })
      // }
      if (this.checkNetWork()) {
        this.CHECKITEMS = [];
        if (type) {
          let params = {
            _method: "PMHSE_INSPECTION.selectCheckItems",
            FATHERCLASS: this.FATHERCLASS.join(""),
            CODE_TYPE: this.CHECKPRO.join("")
          };
          let json = {
            FixJSON: JSON.stringify(params)
          };
          this.$ajax({
            url: this.COMMON_URL + "?_viewId=PMHSE_INSPECTION",
            method: "post",
            params: json
            // params:this.signMD5({_method: "PMHSE_INSPECTION.selectCheckItems", FATHERCLASS: this.FATHERCLASS.join(""), CODE_TYPE: this.CHECKPRO.join("")})
          }).then(res => {
            console.log(res);
            this.CHILDCLASS = res.data.list[0].CHILDCLASS;
            var i = 0;
            for (i = 0; i < res.data.list.length; i++) {
              this.checkItems[i] = [res.data.list[i].CHECKITEMS];
            }
            this.checkItems = [this.checkItems];
          }).then(()=>{
              let params1 = {
              FixJSON: JSON.stringify({
                _method: "PMHSE_INSPECTION.selectChildClass",
                FATHERCLASS: this.FATHERCLASS.join(""),
                CHILDCLASS: this.CHILDCLASS
              })
            };
            this.$ajax({
              url: this.COMMON_URL + "?_viewId=PMHSE_INSPECTION",
              method: "post",
              data: params1
              // params: this.signMD5({_method: "PMHSE_INSPECTION.selectChildClass", FATHERCLASS: this.FATHERCLASS.join(""), CHILDCLASS: this.CHILDCLASS})
            }).then(res => {
              this.IMPORTANCE = res.data.list[0].IMPORTANCE;
              this.WEIGHT = res.data.list[0].WEIGHT;
              console.log("IMPORTANCE",this.IMPORTANCE);
              console.log("weight",this.WEIGHT);
            });
          });
        }
      } else {
        //执行离线状态时的任务
        this.CHECKITEMS = [];
        let fatherclass = this.FATHERCLASS.join("");
        let checkpro = this.CHECKPRO.join("");
        if (type) {
          this.$store.state.SQLiteDB.transaction(tx => {
            tx.executeSql(
              'SELECT * FROM PMHSE_CHECKLISTW WHERE FATHERCLASS="' +
                fatherclass +
                '" AND CHECKPRO="' +
                checkpro +
                '"',
              [],
              (tx, result) => {
                console.log("pro", result);
                let subPrj = result.rows;
                var i = 0;
                this.CHILDCLASS = subPrj.item(0).CHILDCLASS;
                for (i = 0; i < subPrj.length; i++) {
                  this.checkItems[i] = [subPrj.item(i).CHECKITEMS];
                }
                this.checkItems = [this.checkItems];
              }
            );
          });

          console.log("offChildClass",this.CHILDCLASS);
          this.$store.state.SQLiteDB.transaction(tx => {
          tx.executeSql(
              'SELECT * FROM PMHSE_SUBCLASSW WHERE FATHERCLASS="' +
                fatherclass +
                '" AND CHILDCLASS="' +
                this.CHILDCLASS +
                '"',
              [],
              (tx, result) => {
                console.log("offtest",result);
                let subPrj = result.rows;
                this.IMPORTANCE = subPrj.item(0).IMPORTANCE;
                this.WEIGHT = subPrj.item(0).WEIGHT;
                console.log("offIMPORTANCE",this.IMPORTANCE);
                console.log("offweight",this.WEIGHT);
              }
            );
          });
        }
      }
    },
    selectChildClass(type) {
      // if (type) {
      //   let params = {
      //     FixJSON: { "_method": "PMHSE_INSPECTION.selectChildClass", "FATHERCLASS": this.FATHERCLASS.join(""), "CHILDCLASS": this.CHILDCLASS }
      //   }
      //   this.$ajax({
      //     url: this.COMMON_URL + "?_viewId=PMHSE_INSPECTION",
      //     method: 'post',
      //     params: params
      //   }).then(res => {
      //     //console.log(res)
      //     this.IMPORTANCE = res.data.list[0].IMPORTANCE;
      //     this.WEIGHT = res.data.list[0].WEIGHT;
      //     //console.log(this.IMPORTANCE,this.WEIGHT);
      //     // this.CHILDCLASS=res.data.list[0].CHILDCLASS;
      //     //  var i=0;
      //     //  for(i=0;i<res.data.list.length;i++){
      //     //   this.checkItems[i] = [res.data.list[i].CHECKITEMS];
      //     //  }
      //     //  this.checkItems=[this.checkItems]
      //   })
      // }
      // if (this.checkNetWork()) {
      //   if (type) {
      //     let params = {
      //       FixJSON: JSON.stringify({
      //         _method: "PMHSE_INSPECTION.selectChildClass",
      //         FATHERCLASS: this.FATHERCLASS.join(""),
      //         CHILDCLASS: this.CHILDCLASS
      //       })
      //     };
      //     this.$ajax({
      //       url: this.COMMON_URL + "?_viewId=PMHSE_INSPECTION",
      //       method: "post",
      //       data: params
      //       // params: this.signMD5({_method: "PMHSE_INSPECTION.selectChildClass", FATHERCLASS: this.FATHERCLASS.join(""), CHILDCLASS: this.CHILDCLASS})
      //     }).then(res => {
      //       console.log(res);
      //       this.IMPORTANCE = res.data.list[0].IMPORTANCE;
      //       this.WEIGHT = res.data.list[0].WEIGHT;
      //     });
      //   }
      // } else {
      //   //执行离线状态时的任务
      //   let fatherclass = this.FATHERCLASS.join("");
      //   if (type) {
      //     this.$store.state.SQLiteDB.transaction(tx => {
      //       tx.executeSql(
      //         'SELECT * FROM PMHSE_SUBCLASSW WHERE FATHERCLASS="' +
      //           fatherclass +
      //           '" AND CHILDCLASS="' +
      //           this.CHILDCLASS +
      //           '"',
      //         [],
      //         (tx, result) => {
      //           console.log("pro", result);
      //           let subPrj = result.rows;
      //           if (this.judgeDeviceType().isIOS) {
      //             this.IMPORTANCE = subPrj.item(0).IMPORTANCE;
      //             this.WEIGHT = subPrj.item(0).WEIGHT;
      //           } else {
      //             this.IMPORTANCE = subPrj[0].IMPORTANCE;
      //             this.WEIGHT = subPrj[0].WEIGHT;
      //           }
      //         }
      //       );
      //     });
      //   }
      // }
    },
    saveSuccess() {
      this.backhome();
    },
    saveErr() {
      this.toastValueErr = false;
    },
    /**
     * 设置默认的检查日期，格式为xxxx-xx-xx
     */
    setDefautlDate() {
      let now = new Date();
      let month = now.getMonth() + 1;
      let day = now.getDate();
      let hour = now.getHours();
      let min = now.getMinutes();
      let sec = now.getSeconds();
      if (month < 10) {
        month = "0" + month;
      }
      if (day < 10) {
        day = "0" + day;
      }
      if (hour < 10) {
        hour = "0" + hour;
      }
      if (min < 10) {
        min = "0" + min;
      }
      if (sec < 10) {
        sec = "0" + sec;
      }
      this.checkDate = now.getFullYear() + "-" + month + "-" + day;
      this.inputDate =
        now.getFullYear() +
        "-" +
        month +
        "-" +
        day +
        " " +
        hour +
        ":" +
        min +
        ":" +
        sec;

      this.dateChange();
    }
  },
  mounted() {
    console.log("安全检查单", this.proDept);
    // if (new Date().getDate() > 10) {
    //   this.inputDate = this.inputDate.substr(0, 10);
    //   this.checkDate = this.inputDate.substr(0, 10);
    // }
    // else {
    //   this.inputDate = this.inputDate.substr(0, 9);
    //   this.checkDate = this.inputDate.substr(0, 9);
    // }
    this.setDefautlDate();

    if (this.checkNetWork()) {
      this.selectFather();
    } else {
      this.selectFatherOffline();
    }
    var greenIcon = L.icon({
      iconUrl: "../src/assets/img/sign-in.png",
      iconSize: [26, 44], // size of the icon
      iconAnchor: [17, 48] // point of the icon which will correspond to marker's location
      //popupAnchor:  [-3, -76] // point from which the popup should open relative to the iconAnchor
    });
    this.pageToken = this.guid(); //this.sPageToken();
    // this.fieldToken = this.guid();
    this.buttonid = this.guid();
    console.log("jahsdkjasdkjh" + this.centerPosition);
    map = L.map("map", {
      center: [22.521671, 113.895794],
      zoom: 13
    });
    L.tileLayer(
      "http://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}",
      //  "http://t0.tianditu.gov.cn/vec_c/wmts?tk=2528436969e251e7e601cb6989d0b8ee",
      {
        subdomains: ["1", "2", "3", "4"],
        attribution: "高德"
      }
    ).addTo(map);
    map.on("click", onMapClick);
    let th = this;
    function onMapClick(e) {
      // var popup = L.popup();
      // popup.setLatLng(e.latlng)
      //      .setContent("You")
      //      .openOn(map);
      //marker = new L.Marker(e.latlng, {draggable:true});
      // marker = new L.Marker(e.latlng, {icon: greenIcon}).addTo(map);
      if (marker) {
        map.removeLayer(marker);
      }
      marker = new L.Marker(e.latlng, { icon: greenIcon }).addTo(map);
      map.addLayer(marker);
      // console.log(e.latlng.lat)
      // console.log(e.latlng.lng)
      // console.log("LatLng("+e.latlng.lat.toString().substr(0,8)+","+e.latlng.lng.toString().substr(0,9)+")")
      th.site =
        "LatLng(" +
        e.latlng.lat.toString().substr(0, 8) +
        "," +
        e.latlng.lng.toString().substr(0, 9) +
        ")";
      // console.log(th.site)
      //th.centerPosition="LatLng("+e.latlng.lat.toString().substr(0,8)+","+e.latlng.lng.toString().substr(0,9)+")";
      // th.centerPosition=e.latlng;
      // console.log(th.centerPosition);
      // console.log(th.centerPosition.Observer.value);
      //marker.bindPopup("<b>Hello world!</b><br />I am a popup.").openPopup();
      // console.log("点击事件")
      // map.removeLayer(L.marker);
      // L.marker(e.latlng, {icon: greenIcon}).addTo(map);
      //var latlng = L.latLng(50.5, 30.5);
      //  L.marker(e.latlng).addTo(map)
      // .bindPopup("北京大厦<br>").openPopup();
      //var marker = L.marker([51.5, -0.09]).addTo(map);
    }

    //console.log(this.centerPosition);
    var locate = this.centerPosition;
    // var long=this.centerPosition;
    var long = locate.slice(locate.indexOf("(") + 1, locate.indexOf(","));
    var latitude = locate.slice(locate.indexOf(",") + 2, locate.indexOf(")"));
    //console.log(long);
    //console.log(latitude);
    //L.marker([long, latitude]).addTo(map).bindPopup("watch函数").openPopup();
    if (marker) {
      map.removeLayer(marker);
    }
    marker = new L.Marker([long, latitude], { icon: greenIcon }).addTo(map);
    map.addLayer(marker);
    map.panTo([long, latitude]);
  },
  watch: {
    centerPosition: {
      handler(newval) {
        //var long=this.centerPosition.toString
        // console.log(this.centerPosition);
        // L.marker([22.521671, 113.895794]).addTo(map).bindPopup("YOU").openPopup();
        var locate = this.centerPosition;
        // var long=this.centerPosition;
        var long = locate.slice(locate.indexOf("(") + 1, locate.indexOf(","));
        var latitude = locate.slice(
          locate.indexOf(",") + 2,
          locate.indexOf(")")
        );
        //console.log(long);
        //console.log(latitude);
        //L.marker([long, latitude]).addTo(map).bindPopup("watch函数").openPopup();
        if (marker) {
          map.removeLayer(marker);
        }
        marker = new L.Marker([long, latitude], { icon: greenIcon }).addTo(map);
        map.addLayer(marker);
      }
    }
  }
};
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
/* .transition-view /deep/.weui-cells__title {
      margin-top: 0.77em;
    margin-bottom: 0.3em;
    padding-left: 15px;
    padding-right: 15px;
    color: #353535;
    font-size: 14px;
} */
/* .transition-view /deep/ .vux-header .vux-header-left .left-arrow:before {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border: 1px solid rgba(0, 0, 0, 0.8);
  border-width: 1px 0 0 1px;
  -webkit-transform: rotate(315deg);
  transform: rotate(315deg);
  top: 8px;
  left: 7px;
} */
/* .transition-view /deep/ .vux-header .vux-header-title {
  line-height: 40px;
  text-align: center;
  font-size: 18px;
  font-weight: 400;
  color: #333;
} */

.userBack-button_save {
  width: 60%;
  height: 40px;
  background-color: #4d86ff;
  border-radius: 2pt;
  border: 1pt solid #4d86ff;
  margin-top: 20pt;
  color: #ffffff;
  font-size: 15px;
  margin-right: auto;
  margin-left: auto;
  margin-bottom: 20pt;
}
#map {
  width: 100%;
  height: 25%;
}
.content {
  width: 100%;
  height: 75%;
}
.transition-view /deep/ .weui-cells__title {
  color: #333;
}
.top-border {
  border-top: 1px solid #f5f5f5;
}
</style>